<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const data =
      {"success":true,"code":10000,"message":"操作成功！","data":[{"id":"1","name":"SAAS企业管理","type":1,"code":"saas-clients","description":"","pid":"0","enVisible":"0"},{"id":"1063313020819738624","name":"查看部门","type":2,"code":"point-dept","description":"查看部门的按钮","pid":"1","enVisible":"0"},{"id":"1063315016368918528","name":"员工管理","type":1,"code":"employees","description":"用户管理菜单","pid":"0","enVisible":"1"},{"id":"1063315194329042944","name":"用户删除按钮","type":2,"code":"point-user-delete","description":"用户删除按钮","pid":"1063315016368918528","enVisible":"1"},{"id":"1063322760811515904","name":"删除用户api","type":3,"code":"API-USER-DELETE","description":"删除api","pid":"1063315194329042944","enVisible":"1"},{"id":"1063327833876729856","name":"组织架构","type":1,"code":"departments","description":"组织架构菜单","pid":"0","enVisible":"1"},{"id":"1063328114689576960","name":"公司设置","type":1,"code":"settings","description":"公司设置菜单","pid":"0","enVisible":"1"},{"id":"1063328310592933888","name":"用户添加按钮","type":2,"code":"POINT-USER-ADD","description":"用户添加按钮","pid":"1063315016368918528","enVisible":"1"},{"id":"1063328532492587008","name":"用户修改按钮","type":2,"code":"POINT-USER-UPDATE","description":"用户修改按钮","pid":"1063315016368918528","enVisible":"1"},{"id":"1064104257952813056","name":"权限管理","type":1,"code":"permissions","description":"权限菜单","pid":"0","enVisible":"1"},{"id":"1146308691438043136","name":"社保","type":1,"code":"social_securitys","description":"社保菜单","pid":"0","enVisible":"1"},{"id":"1151424682926747648","name":"考勤","type":1,"code":"attendances","description":"考勤","pid":"0","enVisible":"1"},{"id":"1151747519034093568","name":"工资","type":1,"code":"salarys","description":"工资模块","pid":"0","enVisible":"1"},{"id":"1156085524669272064","name":"员工自助","type":1,"code":"user12345","description":"员工自助","pid":"0","enVisible":"1"},{"id":"1172702828368498688","name":"审批","type":1,"code":"approvals","description":"审批","pid":"0","enVisible":"1"}]}

        // function dataTrans(data, type) {
        //   return  data.filter(d => d.id === type).map( d => ({
        //         ...d,
        //         children: dataTrans(data,d.id)
        //       }) )
        // }
        // dataTrans(data, '0')
        function dataTransfer(data, pid) {
           return data
           .filter(d => d.pid === pid)
           .map(d => ({
           ...d,
           children: dataTransfer(data, d.id)
           }))
           }
        console.log(dataTransfer(data.data, '0'));
 </script>
</body>
</html>
